/*fq*/
angular.module('indexApp')
    .controller('housesIntroduceCtrl', function ($scope, $state, $rootScope, $http, $stateParams) {
        var vm = this;
        $scope.state = $state;
        vm.http = $rootScope.http;
        vm.note = 0;//初始化通知按钮
        var swiper = new Swiper('.swiper-container', {
            pagination: '.swiper-pagination',
            loop: true,
            paginationClickable: true,
            autoplay: 3000,//可选选项，自动滑动
            observer: true,//修改swiper自己或子元素时，自动初始化swiper
            observeParents: true,//修改swiper的父元素时，自动初始化swiper
            effect: 'cube',
            cube: {
                slideShadows: true,
                shadow: true,
                // shadowOffset: 100,
                // shadowScale: 0.6
            }
        });


        $http({
            method: 'post',
            url: $rootScope.http + 'houses_info',
            data: {
                // id: id
            }
        })
            .then(function successCallback(res) {
                console.log(res.data);
                if (res.data.code == 0) {
                    vm.data = res.data.data.content;
                    $('#content').html(vm.data.content);

                    console.log(vm.note,'3122312313');
                }
            }, function errorCallback(res) {// 请求失败执行代码
                $rootScope.alertError()
            });
        vm.choose = function () {
            bootbox.confirm({
                message: "报名之前需要先填写注册信息，是否确认注册？",
                buttons: {
                    confirm: {
                        label: '确定',
                        className: 'btn-success'
                    },
                    cancel: {
                        label: '取消',
                        className: 'btn-danger'
                    }
                },
                callback: function (result) {
                    console.log('This was logged in the callback: ' + result);
                    if (result) {
                        $state.go('registered', {}, {reload: true});
                    } else {

                    }
                }
            });
        };
        // 获取用户信息
        if ($rootScope.id) {
            $http({
                method: 'post',
                url: sessionStorage.http + 'get_userinfo',
                data: {
                    user_id: $rootScope.id
                }
            })
                .then(function successCallback(res) {
                    console.log(res.data);
                    if (res.data.code == 0) {
                        vm.note = res.data.data.user.note;
                        vm.is_com = res.data.data.user.is_com;
                    }
                }, function errorCallback(res) {// 请求失败执行代码
                    // $rootScope.alertError()
                });
        }
        // 开盘通知
        vm.notice = function () {
            // 获取用户信息
            if ($rootScope.id) {

            } else {
                //设置楼盘跳转参数
                sessionStorage.house = 1;
                window.location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxa5e230c798925e6e&redirect_uri=' + $rootScope.http_main + '&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect';
            }

            if (vm.is_com == 0) {
                vm.choose();
            }
            else {
                $http({
                    method: 'post',
                    url: $rootScope.http + 'user_note',
                    data: {
                        user_id: $rootScope.id
                    }
                })
                    .then(function successCallback(res) {
                        console.log(res.data);
                        if (res.data.code == 0) {
                            $rootScope.alert(res.data.msg,function () {
                                $state.go('main.home')
                            });
                            vm.note = 1;
                        } else {
                            $rootScope.alert('等待开盘',function () {
                                $state.go('main.home')
                            })
                        }
                    }, function errorCallback(res) {// 请求失败执行代码
                        $rootScope.alertError()
                    });
            }

        };
        // 放大照片
        vm.img_M = [];
        vm.openImg = function (img) {
            vm.openImgItem = img;
            vm.img_M.push(vm.openImgItem);
            wx.previewImage({
                current: img, // 当前显示图片的http链接
                urls: vm.img_M // 需要预览的图片http链接列表
            });
        };
    });